﻿using Logistics.EntityFrameworkCore;
using Logistics.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Logistics.Track
{
    public class CargoownerTrackRepository: ICargoownerTrackRepository
    {
        private readonly LogisticsDbContext db;
        public CargoownerTrackRepository(LogisticsDbContext _db)
        {
            db = _db;
        }
        public async Task<Contracttracking> GetCargoownerTrackById(int Id)
        {
            var list = await db.Contracttracking.FindAsync(Id);
            return list;
        }

        public Task<List<Contracttracking>> GetCargoownerTracks()
        {
            string sql = "select a.*,b.NumberId,b.ContractTitle,b.OutsourcingUnit,b.OutsourcingLeader,b.Line,b.Freightrate,b.CharterConditions,b.CharterAmount,b.SigningDate,b.`Handler`,c.`Name` Fname,d.`Name` Oname,e.`Name` Lname from Carriercontracttracking a right join Carry b on a.ContractId=b.Id join field c on b.OutsourcingUnit=c.Id join `owner` d on b.OutsourcingLeader=d.Id join line e on b.Line=e.Id";

            throw new NotImplementedException();
        }

        public async Task<int> Update(Contracttracking ct)
        {
           var list= await db.Contracttracking.FindAsync(ct.Id);
            list.Abnormal = ct.Abnormal;
            list.Condition = ct.Condition;
            db.Entry(list).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return db.SaveChanges();
        }
    }
}
